//
//  YLFuncDetailHeader.m
//  YLFinanceService
//
//  Created by she1323 on 2017/8/25.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLFuncDetailHeader.h"
#import "YLGlobeHeader.h"
#import <Masonry.h>
#import "YLFuncDetailHeader.h"
#import "YLFuncDetailHeaderModel.h"
@interface YLFuncDetailHeader ()
@property (nonatomic, strong) NSMutableArray *labels;
@property (nonatomic, weak) UIImageView *backGroundImageView;
@end

@implementation YLFuncDetailHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    return self;
}


- (void)setOffsetY:(CGFloat)offsetY
{
    _offsetY = offsetY;
    __weak typeof(self) weakSelf = self;
    [_backGroundImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.mas_equalTo(weakSelf).mas_offset(offsetY);
        make.right.mas_equalTo(weakSelf).mas_equalTo(fabs(offsetY));
    }];
    
}

- (void)setUpUI
{
    __weak typeof(self) weakSelf = self;
    UIImageView *backGroundImageView = [[UIImageView alloc] init];
    _backGroundImageView = backGroundImageView;
    [self addSubview:backGroundImageView];
    backGroundImageView.image = [UIImage imageNamed:@"funcBackgroung"];
    [backGroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.mas_equalTo(weakSelf);
        make.bottom.mas_equalTo(weakSelf).mas_offset(-10);
    }];
    CGFloat labelY = 0;
    CGFloat labelW = YLScreenW / 3.0;
    CGFloat labelH = YLScreenW * 450 / 2250.0;
    _labels = [NSMutableArray arrayWithCapacity:3];
    for (NSInteger i = 0; i < 3; i ++) {
        CGFloat labelX = i * labelW;
        UILabel *label = [[UILabel alloc] init];
        label.numberOfLines = 0;
        [_labels addObject:label];
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.frame = CGRectMake(labelX, labelY, labelW, labelH);
        [self addSubview:label];
    }
    
    self.backgroundColor = [UIColor clearColor];
}

- (void)setHeaderTitles:(NSArray *)headerTitles
{
    _headerTitles = headerTitles;
    for (NSInteger i = 0; i < _labels.count; i ++) {
        UILabel *label = _labels[i];
        YLFuncDetailHeaderModel *m = headerTitles[i];
        label.attributedText = [self attStringWithTitle:m.title content:m.content];
    }
}





- (NSMutableAttributedString *)attStringWithTitle:(NSString *)title content:(NSString *)content
{
    NSMutableAttributedString *att1 = [[NSMutableAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13.0f], NSForegroundColorAttributeName : YLColorA(240, 240, 240, 0.7)}];
    
    [att1 appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n\n" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:7.0f]}]];
    
    [att1 appendAttributedString:[[NSMutableAttributedString alloc] initWithString:content attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:17.0f]}]];
    
    return att1;
}

+ (CGRect)headerFrame
{
    return CGRectMake(0, 0, YLScreenW, YLScreenW * 450 / 2250.0 + 10);
}



@end
